package com.xl.bigdata.spark.manager.manager

import org.apache.spark.sql.SparkSession

object SparkSessionSingletonModel {

  @transient private var instance: SparkSession = _

  def getInstance(warehouseLocation: String): SparkSession = {

    if (instance == null) {

      SparkSession.clearActiveSession()
      SparkSession.clearDefaultSession()
      instance = SparkSession.builder()
        .config("spark.sql.warehouse.dir", warehouseLocation)
        .config("spark.sql.broadcastTimeout", 1000)
        .config("spark.sql.shuffle.partitions", "1")
        .enableHiveSupport()
        .getOrCreate()
    }

    return instance
  }

  @transient private var instanceP: SparkSession = _

  def getInstanceP(warehouseLocation: String): SparkSession = {

    if (instance == null) {

      instance = SparkSession.builder()
        .config("spark.sql.warehouse.dir", warehouseLocation)
        .config("spark.sql.broadcastTimeout", 1000)
        .getOrCreate()
    }

    return instance
  }

}
